package com.zaimokuza.cn.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zaimokuza.cn.entity.PageResult;
import com.zaimokuza.cn.entity.action.Action;
import com.zaimokuza.cn.entity.action.vo.ActionInfo;
import com.zaimokuza.cn.mapper.ActionMapper;
import com.zaimokuza.cn.service.ActionService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author zaimokuza
 */
@Service
public class ActionServiceImpl implements ActionService {

    @Resource
    private ActionMapper actionMapper;

    @Override
    public void addAction(Integer type, String userId, String blogId, String commentId) {
        Action action = new Action(userId, type, blogId, commentId);
        actionMapper.insertActionRecord(action);
    }

    @Override
    public void deleteAction(Integer type, String blogId, String commentId) {
        Action action = new Action(null, type, blogId, commentId);
        actionMapper.deleteActionRecord(action);
    }

    @Override
    public PageResult<ActionInfo> getActionPage(String domain, Integer page, Integer size) {
        // 分页
        PageHelper.startPage(page, size);
        // 查询
        Page<ActionInfo> actionPage = actionMapper.queryActionPage(domain);
        // 封装结果并返回
        return PageResult.from(actionPage);
    }

}
